Get Counterfactual Address
In this guide, we will create a smart account and get its counterfactual address using Axir's SDK and Node.js.
To have a better understanding of our SDK feel free to refer our Git repository.
1. Installation 🔨
First! Let's setup a Javascript/Typescript Project in your environment.
make sure you have NPM and Node Engine installed in your system.
Copy paste the below command in your preferred directory.
mkdir axirwallet && cd axirwallet && npm init -y && npm i --save-dev @types/node tslib
Now its time to add our SDK! 🐞
npm i axr-erc4337-sdk
2. Environment Setup 🔨
Create a .env
file in your project with this format:
PRIVATE_KEY = // your EOA private Key
BASE_SEPOLIA_RPC_URL = // your Base Sepolia RPC URL
BASE_SEPOLIA_BUNDLER_URL = // Your Pimlico bundler url for Base Sepolia
The PRIVATE_KEY
corresponds to an EOA Signer that will be the owner of the Smart Account. You can get private keys from wallets like Metamask, Coinbase, TrustWallet, or generate them using ethers or services like web3Auth.
In the Ethereum Virtual Machine (EVM), smart contracts cannot initiate transactions by themselves. An external signer is required to initiate transactions within the EVM.
We recommend using a dedicated RPC Service (Infura, QuickNode, etc.) for your transactions.
3. Create a Smart Wallet 🔨
- TS
- JS
import { AxirCore } from "axr-erc4337-sdk";
import { type Hex } from "viem";
const smartWalletAccount = new AxirCore(
process.env.PRIVATE_KEY as Hex,
process.env.BASE_SEPOLIA_RPC_URL as string,
process.env.BASE_SEPOLIA_BUNDLER_URL as string,
BigInt(0), // salt - you can enter any value
"baseSepolia" // Base Sepolia network
);
const { address } = await smartWalletAccount.getSenderAddress();
console.log("Axir Wallet Address:", address);
import { AxirCore } from "axr-erc4337-sdk";
const smartWalletAccount = new AxirCore(
process.env.PRIVATE_KEY,
process.env.BASE_SEPOLIA_RPC_URL,
process.env.BASE_SEPOLIA_BUNDLER_URL,
0, // salt - you can enter any value
"baseSepolia" // Base Sepolia network
);
const { address } = await smartWalletAccount.getSenderAddress();
console.log("Axir Wallet Address:", address);
Run the code:
npx ts-node index.ts
You should see your counterfactual Address in the terminal:
Axir Wallet Address: 0xC5779CaBaF94B5467a958A57E0Fd5bd71c45A976
Smart accounts have a predetermined address known before deployment. You can transfer funds to this address, and the actual deployment transaction is internally batched with the first transaction. Alternatively, Axir's Paymaster can sponsor this transaction.
Before proceeding with transactions, fund your smart account address with test network tokens. Get test tokens from the Base Sepolia Faucet. Skipping this step might result in the AA21 didn't pay prefund error! 🚀